<template>
  <!-- <div class="time"><p></p>{{time}}</div> -->
  <div>{{ time }}<span>&nbsp;&nbsp;&nbsp;</span>12:00:00</div>
</template>

<script>
export default {
  data() {
    return {
      time: "",
      timer: "", //定义一个定时器的变量
    };
  },
  created() {
    var _this = this;
    this.timer = setInterval(function () {
      //获取当前时间
      var date = new Date();
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      var hour = date.getHours();
      var min = date.getMinutes();
      var s = date.getSeconds();
      if (month < 10) {
        month = "0" + month;
      }
      if (day < 10) {
        day = "0" + day;
      }
      if (hour < 10) {
        hour = "0" + hour;
      }
      if (min < 10) {
        min = "0" + min;
      }
      if (s < 10) {
        s = "0" + s;
      }
      _this.time =
        year + "/" + month + "/" + day + "  " + hour + ":" + min + ":" + s;
    }, 1000);
  },
  // 销毁定时器
  beforeDestroy: function () {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },
};
</script>

<style lang="scss" scoped>
</style>